package com.example.test.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.test.dao.TypeMapper;
import com.example.test.entity.Type;
import com.example.test.service.TypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author decent
 * @Create 2021/4/7 - 17:59
 * @Description
 */
@Service
public class TypeServiceImpl implements TypeService {

    @Resource
    private TypeMapper typeMapper;

    /**
     * 获取品牌类型列表
     *
     * @param pageNumber 页码
     * @param pageSize   每页数量
     * @return id, typeName, iconUrl
     */
    @Override
    public PageInfo<Type> listBrandType(Integer pageNumber, Integer pageSize) {
        return PageHelper.startPage(pageNumber, pageSize).doSelectPageInfo(() -> {
            typeMapper.selectList(Wrappers.<Type>query()
                    .select("type_id", "type_name", "icon_url")
                    .orderByAsc("sequence"));
        });
    }

    /**
     * 获取品牌类型列表
     *
     * @return id, typeName, iconUrl
     */
    public List<Type> listTypes() {
        return
                typeMapper.selectList(Wrappers.<Type>query()
                        .select("type_id", "type_name", "icon_url")
                        .orderByAsc("sequence"));
    }


}
